package by.dkusch.aircompany.model.tables;

import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import by.dkusch.aircompany.model.tables.base.BaseEntity;

@Entity
public class Crew extends BaseEntity<Long> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@NotNull
	@Size(max = 30)
	@Column
	private String code;

	@Size(max = 50)
	@Column
	private String name;

	@Size(max = 250)
	@Column
	private String description;

	@NotNull
	@Column
	private Date startDate;

	@Column
	private Date endDate;

	@ManyToMany(fetch = FetchType.LAZY, targetEntity = Person.class)
	@JoinTable(name = "crew_person", joinColumns = { @JoinColumn(name = "crew_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "person_id", nullable = false, updatable = false) })
	private Set<Person> personSet = new TreeSet<Person>();

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	/**
	 * @return the personSet
	 */
	public Set<Person> getPersonSet() {
		return personSet;
	}

	/**
	 * @param personSet
	 *            the personSet to set
	 */
	public void setPersonSet(Set<Person> personSet) {
		this.personSet = personSet;
	}

}
